\section{Calculus}
\subsection{Derivative}
\index{derivative}
$d(f,x)$ returns the derivative of $f$ with respect to $x$.
The $x$ can be omitted for expressions in $x$.

\medskip
\verb$d(x^2)$
$$2x$$

\bigskip
\noindent
The following table summarizes the various ways to obtain multiderivatives.

\begin{center}
\begin{tabular}{cllllll}
%& & & & {\it alternate form} \\
%\\
$\displaystyle{\partial^2f\over\partial x^2}$ & & \verb$d(f,x,x)$ & & \verb$d(f,x,2)$ \\
\\
$\displaystyle{\partial^2f\over\partial x\,\partial y}$ & & \verb$d(f,x,y)$ \\
\\
$\displaystyle{\partial^{m+n+\cdot\cdot\cdot} f\over\partial x^m\,\partial y^n\cdots}$ & &
\verb$d(f,x,...,y,...)$ & & \verb$d(f,x,m,y,n,...)$ \\
\end{tabular}
\end{center}

%\medskip
%\verb$r=sqrt(x^2+y^2)$

%\verb$d(r,x,y)$
%$${-{xy\over(x^2+y^2)^{3/2}}}$$

\subsection{Gradient}
\index{gradient}

\noindent
The gradient of $f$ is obtained by using a vector for $x$ in $d(f,x)$.

\medskip
\verb$r=sqrt(x^2+y^2)$

\verb$d(r,(x,y))$
$$\left(\matrix{
\displaystyle{{x\over(x^2+y^2)^{1/2}}}\cr
\cr
\displaystyle{{y\over(x^2+y^2)^{1/2}}}\cr
}\right)$$

\medskip
\noindent
The $f$ in $d(f,x)$ can be a tensor function.
Gradient raises the rank by one.

\medskip
\verb$F=(x+2y,3x+4y)$

\verb$X=(x,y)$

\verb$d(F,X)$
$$\left(\matrix{1&2\cr3&4}\right)$$

\subsection{Template functions}
The function $f$ in $d(f)$ does not have to be defined.
It can be a template function with just a name and an argument list.
Eigenmath checks the argument list to figure out what to do.
For example, $d(f(x),x)$ evaluates to itself because $f$ depends on $x$.
However, $d(f(x),y)$ evaluates to zero because $f$ does not depend on $y$.

\medskip
\verb$d(f(x),x)$
$$\partial(f(x),x)$$

\verb$d(f(x),y)$
$$0$$

\verb$d(f(x,y),y)$
$$\partial(f(x,y),y)$$

\verb$d(f(),t)$
$$\partial(f(),t)$$

\medskip
\noindent
As the final example shows, an empty argument list causes
$d(f)$ to always evaluate to itself, regardless
of the second argument.

\medskip
\noindent
Template functions are useful for experimenting with differential forms.
For example, let us check the identity
$$\mathop{\rm div}(\mathop{\rm curl}{\bf F})=0$$
for an arbitrary vector function $\bf F$.

\medskip
\verb$F=(F1(x,y,z),F2(x,y,z),F3(x,y,z))$

\verb$curl(U)=(d(U[3],y)-d(U[2],z),d(U[1],z)-d(U[3],x),d(U[2],x)-d(U[1],y))$

\verb$div(U)=d(U[1],x)+d(U[2],y)+d(U[3],z)$

\verb$div(curl(F))$
$$0$$
